<?php

/**
 * This is the model class for table "m_student".
 *
 * The followings are the available columns in table 'm_student':
 * @property integer $id
 * @property string $department_id
 * @property integer $tahun_ajaran_id
 * @property string $register_date
 * @property string $trial_id
 * @property string $sid
 * @property string $name
 * @property string $nick_name
 * @property string $birth_place
 * @property string $birth_date
 * @property string $gender
 * @property string $citizenship
 * @property string $religion
 * @property string $ethnic
 * @property string $address
 * @property string $propinsi
 * @property string $kota
 * @property string $area
 * @property string $post_code
 * @property string $home_phone
 * @property string $handphone
 * @property string $email
 * @property string $asal_sekolah
 * @property string $keterangan_asal_sekolah
 * @property string $gol_darah
 * @property integer $berat_kg
 * @property integer $tinggi_cm
 * @property string $riwayat_penyakit
 * @property string $alamat_surat
 * @property string $restriction
 * @property integer $create_bca_va
 * @property string $bca_va_no
 * @property string $payment_method
 * @property string $ref_payment
 * @property string $status_siswa
 * @property integer $is_active
 * @property string $informasi_akademi
 * @property string $insert_date
 * @property string $last_update_date
 * @property string $delete_date
 * @property integer $last_user_id
 *
 * The followings are the available model relations:
 * @property MPenilaian[] $mPenilaians
 * @property MDepartment $department
 * @property MTahunAjaran $tahunAjaran
 * @property MUser $lastUser
 * @property MStudentClass[] $mStudentClasses
 * @property MStudentFamily[] $mStudentFamilies
 * @property MStudentHinvoice[] $mStudentHinvoices
 * @property MStudentHpayment[] $mStudentHpayments
 * @property MUser[] $mUsers
 */
class MStudent extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'm_student';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('department_id, tahun_ajaran_id, register_date, trial_id, name, birth_place, birth_date, insert_date', 'required'),
			array('tahun_ajaran_id, berat_kg, tinggi_cm, create_bca_va, is_active, last_user_id', 'numerical', 'integerOnly'=>true),
			array('department_id, home_phone, handphone, payment_method, status_siswa', 'length', 'max'=>20),
			array('trial_id, sid', 'length', 'max'=>50),
			array('name, nick_name', 'length', 'max'=>255),
			array('birth_place, citizenship, religion, ethnic, propinsi, kota, area, email, asal_sekolah, bca_va_no, ref_payment', 'length', 'max'=>100),
			array('gender', 'length', 'max'=>1),
			array('post_code', 'length', 'max'=>10),
			array('gol_darah', 'length', 'max'=>2),
			array('address, keterangan_asal_sekolah, riwayat_penyakit, alamat_surat, restriction, informasi_akademi, last_update_date, delete_date', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, department_id, tahun_ajaran_id, register_date, trial_id, sid, name, nick_name, birth_place, birth_date, gender, citizenship, religion, ethnic, address, propinsi, kota, area, post_code, home_phone, handphone, email, asal_sekolah, keterangan_asal_sekolah, gol_darah, berat_kg, tinggi_cm, riwayat_penyakit, alamat_surat, restriction, create_bca_va, bca_va_no, payment_method, ref_payment, status_siswa, is_active, informasi_akademi, insert_date, last_update_date, delete_date, last_user_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'mPenilaians' => array(self::HAS_MANY, 'MPenilaian', 'student_id'),
			'department' => array(self::BELONGS_TO, 'MDepartment', 'department_id'),
			'tahunAjaran' => array(self::BELONGS_TO, 'MTahunAjaran', 'tahun_ajaran_id'),
			'lastUser' => array(self::BELONGS_TO, 'MUser', 'last_user_id'),
			'mStudentClasses' => array(self::HAS_MANY, 'MStudentClass', 'student_id'),
			'mStudentFamilies' => array(self::HAS_MANY, 'MStudentFamily', 'student_id'),
			'mStudentHinvoices' => array(self::HAS_MANY, 'MStudentHinvoice', 'student_id'),
			'mStudentHpayments' => array(self::HAS_MANY, 'MStudentHpayment', 'student_id'),
			'mUsers' => array(self::HAS_MANY, 'MUser', 'student_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'department_id' => 'Department',
			'tahun_ajaran_id' => 'Tahun Ajaran',
			'register_date' => 'Register Date',
			'trial_id' => 'Trial',
			'sid' => 'Sid',
			'name' => 'Name',
			'nick_name' => 'Nick Name',
			'birth_place' => 'Birth Place',
			'birth_date' => 'Birth Date',
			'gender' => 'Gender',
			'citizenship' => 'Citizenship',
			'religion' => 'Religion',
			'ethnic' => 'Ethnic',
			'address' => 'Address',
			'propinsi' => 'Propinsi',
			'kota' => 'Kota',
			'area' => 'Area',
			'post_code' => 'Post Code',
			'home_phone' => 'Home Phone',
			'handphone' => 'Handphone',
			'email' => 'Email',
			'asal_sekolah' => 'Asal Sekolah',
			'keterangan_asal_sekolah' => 'Keterangan Asal Sekolah',
			'gol_darah' => 'Gol Darah',
			'berat_kg' => 'Berat Kg',
			'tinggi_cm' => 'Tinggi Cm',
			'riwayat_penyakit' => 'Riwayat Penyakit',
			'alamat_surat' => 'Alamat Surat',
			'restriction' => 'Restriction',
			'create_bca_va' => 'Create Bca Va',
			'bca_va_no' => 'Bca Va No',
			'payment_method' => 'Payment Method',
			'ref_payment' => 'Ref Payment',
			'status_siswa' => 'Status Siswa',
			'is_active' => 'Is Active',
			'informasi_akademi' => 'Informasi Akademi',
			'insert_date' => 'Insert Date',
			'last_update_date' => 'Last Update Date',
			'delete_date' => 'Delete Date',
			'last_user_id' => 'Last User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('department_id',$this->department_id,true);
		$criteria->compare('tahun_ajaran_id',$this->tahun_ajaran_id);
		$criteria->compare('register_date',$this->register_date,true);
		$criteria->compare('trial_id',$this->trial_id,true);
		$criteria->compare('sid',$this->sid,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('nick_name',$this->nick_name,true);
		$criteria->compare('birth_place',$this->birth_place,true);
		$criteria->compare('birth_date',$this->birth_date,true);
		$criteria->compare('gender',$this->gender,true);
		$criteria->compare('citizenship',$this->citizenship,true);
		$criteria->compare('religion',$this->religion,true);
		$criteria->compare('ethnic',$this->ethnic,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('propinsi',$this->propinsi,true);
		$criteria->compare('kota',$this->kota,true);
		$criteria->compare('area',$this->area,true);
		$criteria->compare('post_code',$this->post_code,true);
		$criteria->compare('home_phone',$this->home_phone,true);
		$criteria->compare('handphone',$this->handphone,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('asal_sekolah',$this->asal_sekolah,true);
		$criteria->compare('keterangan_asal_sekolah',$this->keterangan_asal_sekolah,true);
		$criteria->compare('gol_darah',$this->gol_darah,true);
		$criteria->compare('berat_kg',$this->berat_kg);
		$criteria->compare('tinggi_cm',$this->tinggi_cm);
		$criteria->compare('riwayat_penyakit',$this->riwayat_penyakit,true);
		$criteria->compare('alamat_surat',$this->alamat_surat,true);
		$criteria->compare('restriction',$this->restriction,true);
		$criteria->compare('create_bca_va',$this->create_bca_va);
		$criteria->compare('bca_va_no',$this->bca_va_no,true);
		$criteria->compare('payment_method',$this->payment_method,true);
		$criteria->compare('ref_payment',$this->ref_payment,true);
		$criteria->compare('status_siswa',$this->status_siswa,true);
		$criteria->compare('is_active',$this->is_active);
		$criteria->compare('informasi_akademi',$this->informasi_akademi,true);
		$criteria->compare('insert_date',$this->insert_date,true);
		$criteria->compare('last_update_date',$this->last_update_date,true);
		$criteria->compare('delete_date',$this->delete_date,true);
		$criteria->compare('last_user_id',$this->last_user_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return MStudent the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
